public class CompareVersion {

    public int compareVersion1(String version1, String version2) {
        String[] str1 = version1.split("\\.");
        String[] str2 = version2.split("\\.");
        int m = str1.length;
        int n = str2.length;
        for (int i = 0; i < m || i < n; i++) {
            int a = 0;
            if (i < m) a = Integer.parseInt(str1[i]);
            int b = 0;
            if (i < n) b = Integer.parseInt(str2[i]);
            if (a < b) return -1;
            if (a > b) return 1;
        }
        return 0;
    }

    public int compareVersion(String version1, String version2) {
        int m = version1.length();
        int n = version2.length();
        int i = 0;
        int j = 0;
        while (i < m || j < n) {
            int a = 0;
            for (; i < m && version1.charAt(i) != '.'; i++) {
                a = a * 10 + version1.charAt(i) - 48;
            }
            i++;
            int b = 0;
            for (; j < n && version2.charAt(j) != '.'; j++) {
                b = b * 10 + version2.charAt(j) - 48;
            }
            j++;
            if (a > b) return 1;
            if (a < b) return -1;
        }
        return 0;
    }
}
